<template>
  <div class="chart-properties">
    <el-form label-position="top">
      <el-form-item label="图表类型">
        <el-select
          v-model="properties.type"
          placeholder="请选择图表类型"
          @change="updateProperties">
          <el-option label="折线图" value="line" />
          <el-option label="柱状图" value="bar" />
          <el-option label="饼图" value="pie" />
          <el-option label="散点图" value="scatter" />
          <el-option label="雷达图" value="radar" />
        </el-select>
      </el-form-item>

      <el-form-item label="标题设置">
        <el-input
          v-model="properties.title"
          placeholder="图表标题"
          @change="updateProperties" />
      </el-form-item>

      <el-form-item label="数据配置">
        <el-tabs v-model="activeTab">
          <el-tab-pane label="数据源" name="dataSource">
            <el-radio-group
              v-model="properties.dataSource"
              @change="updateProperties">
              <el-radio label="static">静态数据</el-radio>
              <el-radio label="api">接口数据</el-radio>
            </el-radio-group>

            <template v-if="properties.dataSource === 'static'">
              <el-input
                v-model="properties.staticData"
                type="textarea"
                :rows="5"
                placeholder="请输入JSON格式的数据"
                @change="updateProperties" />
            </template>

            <template v-else>
              <el-input
                v-model="properties.apiUrl"
                placeholder="请输入接口地址"
                @change="updateProperties" />
            </template>
          </el-tab-pane>

          <el-tab-pane label="样式配置" name="style">
            <el-form-item label="图表尺寸">
              <el-row :gutter="10">
                <el-col :span="12">
                  <el-input-number
                    v-model="properties.width"
                    :min="0"
                    placeholder="宽度"
                    @change="updateProperties" />
                </el-col>
                <el-col :span="12">
                  <el-input-number
                    v-model="properties.height"
                    :min="0"
                    placeholder="高度"
                    @change="updateProperties" />
                </el-col>
              </el-row>
            </el-form-item>

            <el-form-item>
              <el-checkbox
                v-model="properties.showLegend"
                @change="updateProperties">
                显示图例
              </el-checkbox>
            </el-form-item>

            <el-form-item>
              <el-checkbox
                v-model="properties.showTooltip"
                @change="updateProperties">
                显示提示框
              </el-checkbox>
            </el-form-item>
          </el-tab-pane>
        </el-tabs>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'

const props = defineProps({
  value: {
    type: Object,
    default: () => ({
      type: 'line',
      title: '',
      dataSource: 'static',
      staticData: '',
      apiUrl: '',
      width: 600,
      height: 400,
      showLegend: true,
      showTooltip: true
    })
  }
})

const emit = defineEmits(['update'])

const properties = ref({ ...props.value })
const activeTab = ref('dataSource')

watch(() => props.value, (newVal) => {
  properties.value = { ...newVal }
}, { deep: true })

const updateProperties = () => {
  emit('update', { ...properties.value })
}
</script> 